<?php
namespace App\Api\Movie;

use PhalApi\Api;
/**
 * 登录接口
 */
class Login extends Api
{
    public function getRules()
    {
        return array(
            'login'=> array(
                'username' => array('name' => 'username', 'require' => true),
                'password'=>array('name'=> 'password','require'=>true)
            ),
            'getUserInfo' => array(
            ),
            'token' => array()
        );
    }
    /**
     * 用户登录接口
     * @return array data[0].data 用户信息
     * @desc 用于用户提供信息进行登录
     */
    public function login(){
        if($this->username !='admin'){
            return 1001;
        }
        if($this->password !='git@iteam!34'){
            return 1002;
        }
        $arr = array('code' => 200, 'data'=>array('roles' =>  array('admin'), 'introduction' => '我是一个管理员', 'avatar' => 'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif','name' => 'admin','token' => 'admin','token'=>'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1OTUxNDIzMzQsInN1YiI6IjQifQ.3pdVG5eJIdNyNOdFiJG4GvQ9Y7bij73nW6UBBhL8b94'));
        return $arr;
    }
    /**
     * 获取用户信息
     * @desc 获取用户信息
     */
    public function getUserInfo() {
        $arr = array('code' => 200, 'data'=>array('roles' =>  array('admin'), 'introduction' => '我是一个管理员', 'avatar' => 'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif','name' => 'admin','token' => 'admin','token'=>'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1OTUxNDIzMzQsInN1YiI6IjQifQ.3pdVG5eJIdNyNOdFiJG4GvQ9Y7bij73nW6UBBhL8b94'));
        return $arr;
    }
    /**
     * 用户退出登录
     * @desc 用于用户退出登录
     */
    public function loginOut() {
        return array();
    }
    /**
     * 获取首页数据
     * @desc 获取首页数据
     */
    public function index() {
        $data = [];
        for ($i=7;$i>0,$i--;){
            $data[] = [
                'date'=>date('Y-m-d',strtotime("-$i day",time())),
                'PV' => rand(1000,7000)
            ];
        }
        return $data;
    }

}
